<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<script type="text/javascript">
	$(function(){
		
		$('#registerCou').click(function(){
			window.open('registerCou.do','쿠폰 등록','top=200px,left=600px,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=250,height=400');
		});
		
		$('#pointChange').click(function(){
			
			var historyList = document.getElementById('history');
			var history = 'history=' + historyList[historyList.selectedIndex].innerHTML;
			var point = 'point=' + document.getElementById('pointOutput').value;
			var data = history + '&' + point;

			$.ajax({
				url:"adminPoint.do",
				type:"post",
				data:data,
				dataType:"json",
				success:function(data){
					
					if(data.result == 'success'){
						$('#changeResult').html('변경 되었습니다.').css('color','red');
					}else if(data.result == 'failure'){
						$('#changeResult').html('오류 발생!!').css('color','red');
					}else if(data.result == 'noWork'){
						$('#changeResult').html('변경할 포인트를 선택하세요.').css('color','red');
					}
				}
			});
		});
		
	}); 
	
	function history(obj) {
		var getObj = obj[obj.selectedIndex].innerHTML;
		var point = 0;
		$('#changeResult').html('');
		
		$.getJSON('adminPoint.do', {history:getObj}, function(data){
			point = data.point;
			$("#pointOutput").val(point);
		});
	}
	
</script>


<div class="container">
<div id="info">
	<h2><img src="./image/title_img23.jpg"/></h2>
</div>
	<div id="couDiv">
	<div id="couForm">
		
		<div id="point" align="right" style="margin-top: -30px; margin-bottom: 20px; margin-right:10px;">
			포인트 관리
			<select name="history" id="history" onChange="javascript:history(this)">
				<option value="선택" selected>선택</option>
				<c:forEach var="aPointList" items="${aPointList}" varStatus="status">
					<option value="${aPointList.history}">${aPointList.history}</option>
				</c:forEach>
			</select>
			<input type="text" id="pointOutput">Point
			<button id="pointChange" class="btn btn-info btn-sm" name="pointChange">포인트 변경</button>
			<span id="changeResult"></span>
		</div>
			
		<form action="aCouDelHid.do" method="post" name="aCouDelHid">
			<div class="table-responsive couForm2">
				<table class="table">
					<thead>
						<tr>
							<th>이미지</th>
							<th>쿠폰 아이디</th>
							<th>쿠폰명</th>
							<th>쿠폰 수량</th>
							<th>구매 포인트</th>
							<th>등록 날짜</th>
							<th>쿠폰 숨기기</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach var="aCouList" items="${aCouList}" varStatus="status">
							<tr>
								<td>
									<img src="${pageContext.request.contextPath}/upload/coupon/${aCouList.image}" width="60px" height="60px">
								</td>
								<td style="vertical-align: middle; font-size: 18px"><input type="hidden" name="${status.count}" value="${aCouList.cou_id}">${aCouList.cou_id}</td>
								<td style="vertical-align: middle; font-size: 18px">${aCouList.cou_name}</td>
								<td style="vertical-align: middle;">${aCouList.count}</td>
								<td style="vertical-align: middle;">${aCouList.use_point}</td>
								<td style="vertical-align: middle;">${aCouList.reg_date}</td>
								<td style="vertical-align: middle; padding-left:40px">
									<c:if test="${aCouList.show == 'N'}">
										<input type="checkbox" name="hiding[${status.count}]" value="true" checked="checked">
									</c:if>
									<c:if test="${aCouList.show == 'Y'}">
										<input type="checkbox" name="hiding[${status.count}]" value="true">
									</c:if>
								</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			
			<div align="right" style="margin-top:5%;">
				<input type="hidden" name="aCouListSize" id="aCouListSize" value="${aCouListSize}">
				<input type="button" class="btn btn-info btn-sm" id="registerCou" value="쿠폰 등록">
				<input type="submit" class="btn btn-default btn-sm" id="changeSave" value="변경사항 저장">
			</div>
		</form>
	</div>
	</div>
	
	

</div>





